using UnityEngine;

public class PlayerControll : MonoBehaviour
{
    public float moveSpeed = 3;
    private Rigidbody _r;
    private Animator _animator;
    private float _h;
    public float jumpSpeed = 1.5f;
    private bool _isJumpPressed;
    private bool _doubleJump;
    // Start is called before the first frame update
    void Start()
    {
        _r = GetComponent<Rigidbody>();
    }

    void Update()
    {
        if (Input.GetKeyDown(KeyCode.Space))
        {
            Debug.Log("1");
            _isJumpPressed = true;
        }
    }

    // Update is called once per frame
    void FixedUpdate()
    {
        Walk();
        Jump();
    }
    private void Walk()
    {
        _h = Input.GetAxis("Horizontal");
        transform.Translate(Vector3.right * (moveSpeed * _h * Time.fixedDeltaTime), Space.World);
    }
    private void Jump()
    {
        if (_isJumpPressed)
        {
                _r.velocity = new(_r.velocity.x, jumpSpeed);
                _doubleJump = true;
             if (_doubleJump)
             {
                 _r.velocity = new(_r.velocity.x, jumpSpeed);
                 _doubleJump = false;
             }
             _isJumpPressed = false;
        }
    }
  
}
